//Date Range Picker
$(document).ready(function() {
    $('#reportrange').daterangepicker({
            startDate: moment().subtract('days', 29),
            endDate: moment(),
            minDate: '01/01/2012',
            maxDate: '12/31/2014',
            dateLimit: {
                days: 60
            },
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: false,
            timePickerIncrement: 1,
            timePicker12Hour: true,
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
                'Last 7 Days': [moment().subtract('days', 6), moment()],
                'Last 30 Days': [moment().subtract('days', 29), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
            },
            opens: 'left',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary',
            cancelClass: 'btn-small',
            format: 'MM/DD/YYYY',
            separator: ' to ',
            locale: {
                applyLabel: 'Submit',
                fromLabel: 'From',
                toLabel: 'To',
                customRangeLabel: 'Custom Range',
                daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
                monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                firstDay: 1
            }
        },
        function(start, end) {
            console.log("Callback has been called!");
            $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }
    );
    //Set the initial state of the picker label
    $('#reportrange span').html(moment().subtract('days', 29).format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
});



// Morris chart examples.
$(document).ready(function() {
	new Morris.Bar({
	// ID of the element in which to draw the chart.
	element: 'morris-chart-revenue',
	// Chart data records -- each entry in this array corresponds to a point on
	// the chart.
	data: [
		{ year: '2006', a: 10, b: 10 },
		{ year: '2007', a: 75,  b: 65 },
		{ year: '2008', a: 50,  b: 40 },
		{ year: '2009', a: 75,  b: 65 },
		{ year: '2010', a: 50,  b: 40 },
		{ year: '2011', a: 75,  b: 65 },
		{ year: '2012', a: 100, b: 90 },
		{ year: '2013', a: 70, b: 50 }
	],
	// The name of the data record attribute that contains x-values.
	xkey: 'year',
	// A list of names of data record attributes that contain y-values.
	ykeys: ['a', 'b'],
	 yLabelFormat: function(y) {
        return y + " M";
	 },
	// Labels for the ykeys -- will be displayed when you hover over the
	// chart.
	labels: ['in $', 'in $'],
	grid: true,
	smooth: true,
	resize: true,
	barColors: ['#2a2a2a', '#777777'],
	gridTextColor: ['#717171'],
	hideHover: 'auto'
	});
});


// home page portlet sortable for large and medium devices.
jQuery(document).ready(function(){
	if (jQuery(window).width() > 991) {
		$(document).ready(function() {
			$('.sortable .row').sortable({ 
				axis: 'x'
			});
		});
      }
    });

jQuery(window).resize(function () {
	if (jQuery(window).width() > 991) {
		$(document).ready(function() {
			$('.sortable .row').sortable( "enable" );
			$('.sortable .row').sortable({ 
				axis: 'x'
			});
		});
     }
	else {
	$('.sortable .row').sortable( "disable" );
     }		
});

//For users List demo at dashboard
$(document).ready(function() {
	$(function() {    
        $('#input-quicklist').on('keyup', function() {
          var rex = new RegExp($(this).val(), 'i');
            $('.quick-list .items').hide();
            $('.quick-list .items').filter(function() {
                return rex.test($(this).text());
            }).show();
        });
    });
});